<!DOCTYPE html>

<html lang="zh-hans">
<head>
    <title>发送信息 | 管理系统</title>
    <link rel="stylesheet" type="text/css" href="/static/admin/css/base.css">
    <link rel="stylesheet" type="text/css" href="/static/admin/css/forms.css">
    <script type="text/javascript" src="/admin/jsi18n/"></script>
    <script type="text/javascript" src="/static/admin/js/vendor/jquery/jquery.js"></script>
    <script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>
    <script type="text/javascript" src="/static/admin/js/core.js"></script>
    <script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js"></script>
    <script type="text/javascript" src="/static/admin/js/actions.js"></script>
    <script type="text/javascript" src="/static/admin/js/urlify.js"></script>
    <script type="text/javascript" src="/static/admin/js/prepopulate.js"></script>
    <script type="text/javascript" src="/static/admin/js/vendor/xregexp/xregexp.js"></script>

    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <link href="https://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script>

    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/static/admin/css/responsive.css">
    <meta name="robots" content="NONE,NOARCHIVE">
</head>

<body class="popup  app-blog model-source change-form"
      data-admin-utc-offset="28800">
<!-- Container -->
<div id="container">
    <!-- Content -->
    <div id="content" class="colM">
        <h1>增加 信息</h1>
        <div id="content-main">
            <form id="source_form" method="post">
                <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
                <div>
                    <fieldset class="module aligned ">
                        <div class="form-row">
                            <div>
                                <input type="hidden" id="phones" value="{{ phones }}">
                                <label for="{{ form.phone.id_for_label }}"
                                       id="phone-lable">{{ form.phone.label }}</label>
                                {{ form.phone }}
                                <small class="">{{ form.phone.errors }}</small>
                                <script type="text/javascript" src="/static/admin/js/vendor/jquery/jquery.js"></script>
                                <script>
                                    // 设置手机号输入是否可读
                                    let phones = $("#phones").val();
                                    if (phones.length > 0) {
                                        $("#id_phone").attr({
                                                "value": phones,
                                                "readonly": "readonly"
                                            }
                                        );
                                        $("#phone-lable").html("你选择的手机号码")
                                    }
                                </script>
                            </div>
                        </div>

                        <div class="form-row">
                            <div>
                                <label for="{{ form.content.id_for_label }}">{{ form.content.label }}</label>
                                {{ form.content }}
                                <small class="">{{ form.content.errors }}</small>
                            </div>
                        </div>

                        <div class="form-row">
                            <div>
                                <label for="{{ form.test_select.id_for_label }}">{{ form.test_select.label }}</label>
                                {{ form.test_select }}
                                <small class="">{{ form.test_select.errors }}</small>
                            </div>
                        </div>

                        <div class="form-row">
                            <div>
                                <label for="{{ form.test_select1.id_for_label }}">{{ form.test_select1.label }}</label>
                                {{ form.test_select1 }}
                                <small class="">{{ form.test_select1.errors }}</small>
                            </div>
                        </div>
                    </fieldset>

                    <div class="submit-row">
                        <a href="javascript:window.opener=null;window.open('','_self');window.close();"
                           class="closelink" id="close_pc" style="display:none">关闭</a>

                        {#                        <a href="#" onClick="javascript:history.back(-1);" class="closelink" id="close_phone"#}
                        {#                           style="display: none">关闭</a>#}

                        <a href="{{ pre_page_url }}" class="closelink" id="close_phone"
                           style="display: none">关闭</a>

                        {#                        <input type="submit" value="发送" class="default" name="_save" id="submit" onclick="submit()">#}
                        <input type="button" class="default" onclick="send_mes()" value="发送">
                    </div>

                    <script type="text/javascript"
                            id="django-admin-form-add-constants"
                            src="/static/admin/js/change_form.js"
                            data-model-name="source">
                    </script>
                    <script type="text/javascript"
                            id="django-admin-prepopulated-fields-constants"
                            src="/static/admin/js/prepopulate_init.js"
                            data-prepopulated-fields="[]">
                    </script>

                </div>
            </form>
            <script>
                // 关闭适应 手机端 和 PC 端
                try {
                    if (/Android|iOS|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)) {
                        $("#close_phone").attr("style", "display:block;");
                    } else {
                        $("#close_pc").attr("style", "display:inline-block;");
                    }
                } catch (e) {
                    console.log("设置失败")
                }

                // 发送
                function send_mes() {
                    {#$("#source_form").submit(function () {#}
                    $.ajax({
                        url: '/blog/add_info',
                        type: "POST",
                        dataType: "json",
                        async: false,
                        data: {
                            "csrfmiddlewaretoken": "{{ csrf_token }}",
                            "phone": $('input[name="phone"]').val(),
                            "content": $('input[name="content"]').val(),
                            "test_select": $('input[name="test_select"]:checked').val(),
                            "test_select1": $("#id_test_select1 option:selected").val(),
                        },
                        success: function (responese) {
                            {#console.log(responese);#}
                            if (responese.status < 400) {
                                toastr.info(responese.msg);
                                setTimeout(function () {
                                    if (/Android|iOS|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)) {
                                        window.location.href = "{{ pre_page_url }}";
                                    } else {
                                        window.close();
                                    }
                                }, 2500);
                            } else {
                                toastr.warning(responese.msg);
                            }
                        },
                        error: function () {
                            toastr.warning("请填写内容");
                        }
                    })
                }
            </script>

        </div>
        <br class="clear">
    </div>
    <!-- END Content -->

    <div id="footer"></div>
</div>
<!-- END Container -->

</body>
</html>
